$(document).ready(function () { 
	//禁止缓存
	if(!window.name){         
		var str = Math.random().toString(36).substr(2);
		window.location.href += '?S='+ str;
		window.name = 'isreload';
	}

	 $.ajax({
                url: "http://jdt.yyfai.club/jdt.php?mode=chaxun",
                type:'GET',
                dataType: 'json', 
                data: {},
                
                error:function(data, XMLHttpRequest, textStatus, errorThrown){  
					alert(data);  
					alert(XMLHttpRequest.status);  
					alert(XMLHttpRequest.readyState);  
					alert(textStatus);},
                success: function(response) {
                    
                creat(response);
                // $("#yname").attr("value",response.yname);
                // $('#zubie').val(response.zubie);
                // $('#zhiwu').val(response.zhiwu);
                // alert('添加成功!');
    
                }
           });
	 $("#mmodify").click(function(){
	 	var pid = prompt("请输入进度条id","");
	 	var name = prompt("请输入进度条名字","");
	 	var percentage = prompt("请输入进度","");
	 	var color = prompt("请输入进度条颜色","");
	 	$.ajax({
                url: "http://jdt.yyfai.club/jdt.php?mode=modify",
                type:'POST',
                data: {'pid':pid,'name':name,'percentage':percentage,'color':color},
                
                error:function(data, XMLHttpRequest, textStatus, errorThrown){  
					alert(data);  
					alert(XMLHttpRequest.status);  
					alert(XMLHttpRequest.readyState);  
					alert(textStatus);
					alert('修改失败');
				},
                success: function(response) {
                   	alert('修改成功');
                }
           });
	 });
	 $("#aadd").click(function(){
	 	var name = prompt("请输入进度条名字","");
	 	var percentage = prompt("请输入进度","");
	 	var color = prompt("请输入进度条颜色","");
	 	$.ajax({
                url: "http://jdt.yyfai.club/jdt.php?mode=creat",
                type:'POST',
                data: {'name':name,'percentage':percentage,'color':color},
                
                error:function(data, XMLHttpRequest, textStatus, errorThrown){  
					alert(data);  
					alert(XMLHttpRequest.status);  
					alert(XMLHttpRequest.readyState);  
					alert(textStatus);
					alert('添加失败');
				},
                success: function(response) {
                   	alert('添加成功');
                }
           });
	 });

}); 
function creat(response){
	console.log(response);
	var arr = response;
	for (var i = 0; i < arr.length; i++) {
		var pid = arr[i][0];
		var name = arr[i][1];
		var percentage = arr[i][2];
		var color = arr[i][3];
		var colorValue;
		switch(color){
			case "1":
				color = "green";colorValue="#21da9a";
			break;
			case "2":
				color = "pink";colorValue="#ff1170";
			break;
			case "3":
				color = "yellow";colorValue="#ffa900";
			break;
			case "4":
				color = "blue";colorValue="#294bdc";
			break;
		}

		var jdtContent = $("<div class='progress "+color+"' pid='"+pid+"'></div>");
		var jdtLable = $("<h3 class='progress-title'>"+pid+":"+name+"</h3>");
		var jdtBar = $("<div class='progress-bar' style='width:"+percentage+"%; background:"+colorValue+";'><div class='progress-value'>"+percentage+"</div></div>");
		jdtContent.append(jdtLable);
		jdtContent.append(jdtBar);
		$("#ccontent").append(jdtContent);
	}
	$(".progress-title").click(function(){
	 	var percentage = prompt("请输入进度","");
	 	var pid = $(this).parent(".progress").attr("pid");
	 	$.ajax({
                url: "http://jdt.yyfai.club/jdt.php?mode=modify2",
                type:'POST',
                data: {'pid':pid,'percentage':percentage},
                
                error:function(data, XMLHttpRequest, textStatus, errorThrown){  
					alert(data);  
					alert(XMLHttpRequest.status);  
					alert(XMLHttpRequest.readyState);  
					alert(textStatus);
					alert('修改失败');
				},
                success: function(response) {
                   	alert('修改成功');
                }
           });
	 });
	// $("#ccontent")
}